<template>
	<view class="follow">
		<view class="follow-tab">
			<view class="follow-tab__box">
				<view class="follow-tab__item" :class="{active:activeIndex === 0}" @click="tab(0)">文章</view>
				<view class="follow-tab__item" :class="{active:activeIndex === 1}" @click="tab(1)">作者</view>
			</view>
		</view>
		<view class="follow-list">
			<swiper class="follow-list__swiper" :current="activeIndex" @change="change">
				<swiper-item>
					<list-scroll class="follow-list__scroll">
						<list-card v-for="item in list" :key="item._id" :item="item" types="follow"></list-card>
						<uni-load-more v-if="list.length === 0 && !show" iconType="snow" status="loading"></uni-load-more>
						<view class="no-data" v-if="show">没有数据</view>
					</list-scroll>
				</swiper-item>
				<swiper-item>
					<list-scroll>
						<list-author v-for="item in authorList" :key="item.id" :item="item">
						</list-author>
					</list-scroll>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex: 0,
				list: [],
				authorList: [],
				show: false
			}
		},
		onLoad() {
			this.getFollow()
			this.getAuthor()
			uni.$on('changAticleLike', () => {
				this.getFollow()
			})
			uni.$on('changAuthorLike', () => {
				this.getAuthor()
			})
		},
		methods: {
			tab(index) {
				this.activeIndex = index
			},
			getFollow() {
				this.$api.get_follow()
				.then((res) => {
					const { data } = res
					this.list = data
					this.show = this.list.length === 0
				})
			},
			change(event) {
				const { current } = event.detail
				this.activeIndex = current
			},
			getAuthor() {
				this.$api.get_author()
				.then((res) => {
					const { data } = res
					console.log(data)
					this.authorList = data
				})
			}
 		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}
	
	.follow {
		height: 100%;
		display: flex;
		flex-direction: column;
		flex: 1;
		box-sizing: border-box;

		.follow-tab {
			height: 30px;
			padding: 10px 20px;
			border-bottom: 1px #f5f5f5 solid;

			.follow-tab__box {
				display: flex;
				width: 100%;
				height: 100%;
				border-radius: 5px;
				border: 1px $mk-base-color solid;

				.follow-tab__item {
					display: flex;
					justify-content: center;
					align-items: center;
					color: #666;
					font-size: 14px;
					width: 100%;

					&:first-child {
						border-right: 1px $mk-base-color solid;
					}

					&.active {
						color: $mk-base-color;
					}

				}
			}
		}
		
		.follow-list {
			flex: 1;
			.follow-list__swiper {
				height: 100%;
			}
		}
	}
	
	.no-data {
		padding: 50px;
		font-size: 14px;
		text-align: center;
		color: #999;
	}

</style>
